<style lang="less">
@import "../../../assets/style/photo.less";
</style>

<template>
    <mxq-router-layout>
        <div class="photo">
            <Head  slot="header" @headerClick="headerClick($event)">
                <div slot="headerTitle">
                    <span>{{towerName}}杆塔</span>
                </div>
                <div slot="headerRight">
                    <i class="iconfont icon-duigou"/>
                    <!-- <van-icon name="success"></van-icon> -->
                </div>
            </Head>
            
            <span class="iconBox">
                <img
                    class="iconRight"
                    src="../../../assets/img/changguixunshi/icon_rw.png"
                    @click="endTask"/>
                <em class="iconText">{{iconText}}</em>
            </span>

            <!-- 拍照 start -->
            <take-photo
                :pohtoParam="pohtoParam"
                :photoLists="photoLists"
                :pohtoShow="pohtoShow"
                @quexian_data="initQuanxian"/>
            <!-- 拍照 end -->

            <van-row class="quexian_item">
                <van-col span="24">
                    <p class="photo_item tit_item clearfix">
                        <label for="架空线路缺陷核查">架空线路缺陷核查</label>
                    </p>
                </van-col>
            </van-row>
            <!-- 八大线路缺陷 开始 -->
            <quexian-list
                :listLeftImg="listLeftImg" 
                :type_arr="type_arr"
                @quexianClick="quexianClick($event)"/>
            <!-- 八大线路缺陷 结束 -->
            
            <!--一键告警-->
            <img src="../../../assets/img/icon_sos.png"
                class="icon_sos"
                @click="getSos"
                alt=""/>
            <div class="btns">
                <van-tabbar>
                    <van-tabbar-item>
                        <van-button size="small" class="btn_l" @click="goYhList">隐患情况</van-button>
                    </van-tabbar-item>
                    <van-tabbar-item>
                        <van-button size="small" class="btn_r" @click="goClArea">测量记录</van-button>
                    </van-tabbar-item>
                </van-tabbar>
            </div>
            <!-- 弹出层 开始 -->
            <div class="pop_up">
                <van-popup v-model="show">
                    <span class="pop_txt">
                        当前在此杆塔100米范围内所停留时间为0秒，不满足巡视任务杆塔180秒停留作业，是否提交巡视不到位作业？
                    </span>
                    <van-button size="small" class="btn_l">是</van-button>
                    <van-button size="small" class="btn_r">否</van-button>
                </van-popup>
            </div>
            <!-- 弹出层 结束 -->
        </div>
    </mxq-router-layout>
</template>

<script>
import Head from '../../../components/head'
import testPhoto from '../../../assets/img/test.jpg'
import QuexianList from '../../../components/quexian'
import TakePhoto from '../../components/taskTake-photo'
import iconHis from '../../../assets/img/changguixunshi/icon_histroy.png'
import { fileData, callData } from '../../../axios/axios'
import { getLocation } from '../../../api/android'
import { 
    Row,
    Col,
    Tabbar,
	TabbarItem,
    Button,
    Icon,
    Popup,
    Dialog,
    Toast
} from 'vant'

export default {
    components: {
        Head,
        TakePhoto,
        QuexianList,
        [Row.name]: Row,
        [Col.name]: Col,
        [Tabbar.name]:Tabbar,
        [TabbarItem.name]:TabbarItem,
        [Button.name]:Button,
        [Icon.name]:Icon,
        [Popup.name]:Popup,
        [Dialog.name]:Dialog
    },
    data() {
        return {
            towerName: this.$route.query.towerName,
            iconText: '结束任务',
            show: false,
            isHome: false,
            // isEnd: true,    //结束杆塔图标/结束任务图标/拍照图标
            // 历史图标
            listLeftImg:[iconHis,iconHis,iconHis,iconHis,iconHis,iconHis,iconHis,iconHis,iconHis],
            pohtoParam: {
            	taskId: this.$route.query.zsTaskId,
            	towerTaskId: this.$route.query.xsTowerTaskId,
            	towerId: this.$route.query.towerId,
				status: this.$route.query.status,
				towerStatus: this.$route.query.towerStatus //杆塔状态
            },
            pohtoShow: {
            	type: 'bdzs',
            	img: true
            },
            photoLists: [
                {
                    title: "杆塔牌拍照",
                    photo: []
                },
                {
                    title: "杆基拍照",
                    photo: []
                },
                {
                    title: "全塔拍照",
                    photo: []
                },
                {
                    title: "塔头拍照",
                    photo: []
                },
                {
                    title: "大号侧同拍照",
                    photo: []
                },
                {
                    title: "小号侧同拍照",
                    photo: []
                }
            ],
            title: '',
            testPhoto: testPhoto,
            type_arr: {},
            jdwdMeg:{//非安卓环境下参数
	            	lon:'',
	            	lat:'',
	            	address:''
            },
            lon: '',    //安卓经度
            lat: '',    //安卓纬度
            params: this.$route.query   //获取地址栏参数
        }
    },
    created(){
        // this.isShow();
    },
    methods: {
        // 头部两侧按钮点击事件
        headerClick(e){
            this.endTower();
        },
        headerClickHome(){
            this.$router.push({name:"index"})
        },
        // 初始化缺陷数据
        initQuanxian(e){
            this.type_arr = e;
        },
    	// 八大缺陷的点击事件
		quexianClick(e){
            let query = {
                name: e.allName,
                flag: e.FLAG,
                towerId: this.params.towerId,
                towerTaskId: this.params.xsTowerTaskId,
                taskId: this.params.zsTaskId,
                defectType: e.index,
                xsTowerTaskId: this.params.xsTowerTaskId,
                lineTowerId: this.params.lineTowerId,
                lineId: this.params.lineId,
                status: this.params.status,
                lineName: this.params.lineName,
                towerName: this.params.towerName,
                zsTaskId: this.params.zsTaskId,
                page: this.params.page,
                size: this.params.size,
                index: this.params.index
            }
			this.$router.push({
				name:'bdzs_quexianList',
				query: query
			})
		},
        goYhList() {
            this.$router.push({
				name:'bdzs_yinhuanList',
				query : {
					zsTaskId: this.$route.query.zsTaskId,
					towerId:this.$route.query.towerId,
					punchtype:this.$route.query.punchtype,
					lineId:this.$route.query.lineId,
					lineName:this.$route.query.lineName,
					towerStatus: this.params.towerStatus,
					towerName:this.$route.query.towerName,
					taskId :this.$route.query.taskId,
					lineTowerId :this.$route.query.lineTowerId,
					towerTaskId:this.$route.query.towerTaskId,
					page: this.$route.query.page,
					size: this.$route.query.size
	        	}
			})
        },
        goClArea() {
            this.$router.push({
				name:'bdzs_ceLiang',
				query : {
                    towerStatus: this.params.towerStatus,//杆塔状态
                    needMeasure: this.params.needMeasure,//测量限制
					towerId: this.params.towerId,
					lineId: this.params.lineId,
					lineName: this.params.lineName,
					towerName: this.params.towerName,
					taskId: this.params.taskId,
					lineTowerId: this.params.lineTowerId,
					towerTaskId: this.params.towerTaskId
	        	}
			})
            // this.$router.push('/cgxs_ceLiang');
        },
        // 是否显示结束-用于已完成时查看
        /* isShow(){
            if(this.$route.query.status==2){
                this.isEnd = false;
            }
        }, */
        // 结束杆塔
        endTower(){
            Dialog.confirm({
                title: '结束杆塔任务',
                message: '确定要结束该杆塔任务吗？'
            }).then(() => {
                // on confirm
                var params = {};
                params.xsTowerTaskId = this.$route.query.xsTowerTaskId;                
                callData('/zsTaskServer/ZsBdTowerTask/appZsTowerOver', 'put', params).then(res => {
                    if(res.success){
                        Toast(res.data);
                        this.$router.go(-1)
                    }
                    else {
                        Toast(res.data);
                    }
                })
            }).catch(() => {
                // on cancel
            });
        },
        // 结束任务
        endTask() {
            Dialog.confirm({
                title: '结束线路任务',
                message: '确定要结束该线路所关联的杆塔任务吗？'
            }).then(() => {
                // on confirm
                var params = {};
                params.zsTaskId = this.$route.query.zsTaskId;
                callData('/zsTaskServer/ZsBdTowerTask/appZsTaskEnd', 'put', params).then(res => {
                    if(res.success){
                        Toast(res.data);
                        this.$router.push({
                            name:'bdzs_xianluXunshi',
                            query : {
                                router: this.$route.query.router,
                                index: this.$route.query.index
                            }
                        })
                    }
                    else {
                        Toast(res.data);
                    }
                })
            }).catch(() => {
                // on cancel
            });
        },
        // 一键告警
        getSos(){
            Dialog.confirm({
                title: '告警',
                message: '确定要发出告警吗？'
            }).then(() => {
                // on confirm
                if(window.Cordova){
                    getLocation(res => {
                    		var params = {};
                        params.jd = res.data.lon;
                        params.wd = res.data.lat;
                        params.alarmAddress=res.data.address;  // 当前的地理位置
                        console.log('告警jd',res.data.lon);
                        console.log('告警wd',res.data.lat);
                        console.log('告警地址',res.data.address);
                        callData('/statisServer/CmAlarm/saveCmAlarm', 'post', params).then(res => {
                            console.log('告警res==',res);
                            if(res.success){
                            		Toast('告警发送成功');
                            }
                            else {
                            		Toast('告警发送失败');
                        		}
                        })
                    })
                }
                else{
                    var params = {};
                    params.jd = this.jdwdMeg.lon;            //经度 
                    params.wd = this.jdwdMeg.lat;            //纬度
                    params.alarmAddress = this.jdwdMeg.address;// 当前的地理位置
                    callData('/statisServer/CmAlarm/saveCmAlarm', 'post', params).then(res => {
                        if(res.success){
                        		Toast('告警发送成功');
                        }
                        else {
                            Toast('告警发送失败');
                        }
                    })
                }
            }).catch(() => {
                // on cancel
            });
        }
    }
}
</script>